//
//  VoiceCell.m
//  SmileRead
//
//  Created by dllo on 15/8/24.
//  Copyright (c) 2015年 JIZ. All rights reserved.
//

#import "VoiceCell.h"
#import "Mybutton.h"
#import "VoiceModel.h"
#import "Path.h"
#import <AVFoundation/AVFoundation.h>


@interface VoiceCell ()

@property (nonatomic, retain) UIImageView *voiceImage;

@property (nonatomic, retain) UILabel *titleLabel;;

@property (nonatomic, retain) UILabel *authorLabel;

@property (nonatomic, retain) UILabel *descLabel;


@end

@implementation VoiceCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.voiceImage = [[UIImageView alloc] init];
        [self.contentView addSubview:self.voiceImage];
        [_voiceImage release];
        
        self.titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.titleLabel];
        
        [_titleLabel release];
        
        self.authorLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.authorLabel];
       
        [_authorLabel release];
        
        self.descLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.descLabel];
        
        [_descLabel release];
        
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.voiceImage.frame = CGRectMake(10 * widthFit, 20 * heightFit, 110 * widthFit, 110 * heightFit);
    
    self.titleLabel.frame = CGRectMake(130 * widthFit, 20 * heightFit, self.frame.size.width - 130 * widthFit, 40 * heightFit);
    self.titleLabel.numberOfLines = 0;
    self.titleLabel.font = [UIFont systemFontOfSize:20];
    
    self.authorLabel.frame = CGRectMake(130 * widthFit, 60 * heightFit, self.frame.size.width - 130 * widthFit, 20 * heightFit);
    self.authorLabel.numberOfLines = 0;
    self.authorLabel.font = [UIFont systemFontOfSize:14];
    //self.authorLabel.textColor = [UIColor blueColor];
    
    self.descLabel.frame = CGRectMake(130 * widthFit, 80 * heightFit, self.frame.size.width - 140 * widthFit, 50 * heightFit);
    self.descLabel.numberOfLines = 0;
    self.descLabel.font = [UIFont systemFontOfSize:14];
    
}

- (void)setModel:(VoiceModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
        self.titleLabel.text = _model.title;
        NSString *string = [NSString stringWithFormat:@"by %@", [_model.userinfo objectForKey:@"uname"]];
        self.authorLabel.text = string;
        self.descLabel.text = _model.desc;
        [Path pathWithImageView:self.voiceImage URLString:_model.coverimg];
    }
}

- (void)receiveWithModel:(VoiceModel *)model text:(NSString *)text
{
    self.titleLabel.attributedText = [Path lightWithTitle:model.title text:text];
}


- (void)dealloc
{
    [_titleLabel release];
    [_authorLabel release];
    [_descLabel release];
    [_voiceImage release];
    [super dealloc];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
